package com.example.demo_one

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity

class PageTwoActivity : AppCompatActivity() {
    // 定义一个常量
    private val TAG = "itCast_B页面"

    @SuppressLint("MissingInflatedId", "SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_page_two)

        Log.d(TAG, "onCreate")

        // 1. 接受上一个页面传递的参数
        val name = intent.getStringExtra("name")
        val age = intent.getIntExtra("age", 0)
        val height = intent.getFloatExtra("height", 0f)

        // 2. 在页面中显示参数
        findViewById<android.widget.TextView>(R.id.tv_title).text =
            "姓名: $name, 年龄: $age, 身高: $height"

        // 3. 点击返回
        findViewById<android.widget.Button>(R.id.btn_back).setOnClickListener {
            // 返回时给上一个页面传递参数
            var resIntent = Intent().apply {
                putExtra("result_data", "给上一个页面的数据6666")
            }
            // 设置结果码和数据
            setResult(RESULT_OK, resIntent)

            finish()
        }

    }

    override fun onStart() {
        super.onStart()
        Log.d(TAG, "onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG, "onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG, "onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG, "onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy")
    }

    override fun onRestart() {
        super.onRestart()
        Log.d(TAG, "onRestart")
    }
}